/**
 * DaoOils.java
 *2013年9月28日下午9:27:39
 *LINKT
 */
package com.jskj.dao;

import java.sql.ResultSet;
import java.sql.SQLException;


import com.jskj.bean.Oils;
import com.jskj.commons.DBConn;

/**
 * @author LINKT
 *
 */
public class DaoOils {

       
        /**
         * 新增油品信息
         * @param oils
         * @return
         */
        public boolean addOils(Oils oils) {
                DBConn conn=new DBConn();
                if (conn.SelectSQLCount("select * from tax_yp where ypxh_dm='"+oils.getYp_dm()+"'")==0) {
                        conn.ExecuteSQL("insert into tax_yp (ypxh_dm,ypxh_mc,hs,bz,xybz) values('"+oils.getYp_dm()+"','"+oils.getYp_mc()+"','"+oils.getYp_hs()+"','"+oils.getYp_mc()+"','Y')");
                        conn.Close();
                        return true;
                }else{
                        return false;
                }
        }
        /**
         * 更新油品名称和系数
         * @param oils
         * @return
         */
        public boolean updateOils(Oils oils) {
                DBConn conn=new DBConn();
                if (conn.SelectSQLCount("select * from tax_yp where ypxh_dm='"+oils.getYp_dm()+"'")>0) {
                        conn.ExecuteSQL("update tax_yp set ypxh_mc='"+oils.getYp_mc()+"',hs='"+oils.getYp_hs()+"' where ypxh_dm='"+oils.getYp_dm()+"'");
                        conn.Close();
                        return true;
                }else{
                        return false;
                }
        }
        /**
         * 删除油品信息
         * @param oils
         * @return
         */
        public boolean delOils(Oils oils){
                DBConn conn=new DBConn();
                if (conn.SelectSQLCount("select * from tax_yp where ypxh_dm='"+oils.getYp_dm()+"'")>0) {
                        conn.ExecuteSQL("delete tax_yp  where ypxh_dm='"+oils.getYp_dm()+"'");
                        conn.Close();
                }
                return true;
        }
        /**
         * 获取油品列表
         * @return
         */
        public String getOilsList() {
                DBConn conn=new DBConn();
                ResultSet rs=conn.SelectSQL("select * from tax_yp");
                StringBuffer sb=new StringBuffer();
                String str="";
                int totalcount=0;
                try {
                        while (rs.next()) {
                                if (totalcount>0) {
                                        sb.append(",");
                                }
                                sb.append("{\"yp_dm\":\""+rs.getString("ypxh_dm")+"\",\"yp_mc\":\""+rs.getString("ypxh_mc")+"\",\"yp_hs\":\""+rs.getString("hs")+"\"}");
                                totalcount++;
                        }
                        rs.close();
                        conn.Close();
                        str="{\"totalCount\":"+totalcount+",\"items\":["+sb.toString()+"]}";;
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                return str;
        }
}
